import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { resolve } from 'path'
import serverConfig from "./src/config"
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default ({command, mode}) => defineConfig({
	plugins: [
		vue(),
		Components({
			resolvers: [VantResolver()],
		}),
	    AutoImport({
	      resolvers: [ElementPlusResolver()],
	    }),
	    Components({
	      resolvers: [ElementPlusResolver()],
	    }),	
	],
	resolve: {
	     alias: [
			{ find: '@', replacement: resolve(__dirname, 'src') },
			{ find: '_c', replacement: resolve(__dirname, 'src/components') },
			{ find: '_v', replacement: resolve(__dirname, 'src/views') },
		]
	  },
	server: {
		proxy: {
		  '/api': {
			// 根据不同运行环境加载不同的配置文件
			target: loadEnv(mode, process.cwd()).VITE_API_TARGET_URL,
			// 根据配置文件加载
			// target: serverConfig.server.dev,
			changeOrigin: true,
			rewrite: (path) => path.replace(/^\/api/, '')
		  }
	    }
	  },
});

